package com.feilx.changggou.seckill.controller;

import java.util.Arrays;


import com.changgou.bean.PageVo;
import com.changgou.bean.QueryCondition;
import com.changgou.bean.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import com.feilx.changggou.seckill.entity.TbSeckillOrderEntity;
import com.feilx.changggou.seckill.service.TbSeckillOrderService;




/**
 *
 *
 * @author feilx
 * @email 852371260@qq.com
 * @date 2020-08-13 22:04:16
 */
@Api(tags = " 管理")
@RestController
@RequestMapping("order/tbseckillorder")
public class TbSeckillOrderController {

    @Autowired
    private TbSeckillOrderService tbSeckillOrderService;

    /**
     * 下单
     * */
    @ApiOperation(value = "秒杀商品下单")
    @PostMapping("/add")
    public Resp add(@RequestParam("id") String id,
                    @RequestParam("time") String time){
        // 模拟下单用户
        String  userName = "feilx";
       boolean b =  tbSeckillOrderService.add(id,time,userName);
        return null;
    }


    /**
     * 列表
     */
    @ApiOperation("分页查询(排序)")
    @GetMapping("/list")
    public Resp<PageVo> list(QueryCondition queryCondition) {
        PageVo page = tbSeckillOrderService.queryPage(queryCondition);
        return Resp.ok(page);
    }


    /**
     * 信息
     */
    @ApiOperation("详情查询")
    @GetMapping("/info/{id}")
    public Resp<TbSeckillOrderEntity> info(@PathVariable("id") Long id){
		TbSeckillOrderEntity tbSeckillOrder = tbSeckillOrderService.getById(id);
        return Resp.ok(tbSeckillOrder);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @PostMapping("/save")
    public Resp<Object> save(@RequestBody TbSeckillOrderEntity tbSeckillOrder){
		tbSeckillOrderService.save(tbSeckillOrder);

        return Resp.ok(null);
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PostMapping("/update")
    public Resp<Object> update(@RequestBody TbSeckillOrderEntity tbSeckillOrder){
		tbSeckillOrderService.updateById(tbSeckillOrder);

        return Resp.ok(null);
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @PostMapping("/delete")
    public Resp<Object> delete(@RequestBody Long[] ids){
		tbSeckillOrderService.removeByIds(Arrays.asList(ids));

        return Resp.ok(null);
    }

}
